<!DOCTYPE html>
<html>
<head>
    <title>请求位置</title>
</head>
<body>
    <input type="button" onclick="clickLoc()" value="获取位置"/>
    <div id="content"></div>
    <script type="text/javascript">
        window.contentEle = document.getElementById("content");
        function clickLoc(){
            if(navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(onSuccess)
            } else {
                contentEle.innerHTML = '浏览器不支持地理位置定位';
            }
        }
        function onSuccess(position){
            console.log(position);
            let longitude = position.coords.longitude;
            let latitude = position.coords.latitude;
            contentEle.innerHTML = '经度: ' + longitude + ', 纬度: ' + latitude;
        }

        function onFailure(){
            contentEle.innerHTML = '获取位置信息失败';
        }
    </script>
</body>
</html>